package context.event;

import cn.stimd.spring.context.annotation.Configuration;
import cn.stimd.spring.context.event.ApplicationEvent;
import cn.stimd.spring.context.event.EventListener;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
@Configuration
public class EventConfig {

    //监听单一事件
    @EventListener(NewsEvent.class)
    public void newsListener(NewsEvent event){
        System.out.println("张三读 " + event.getSource());
    }


    //监听多个事件，方法参数是较为笼统的ApplicationEvent或Object
    @EventListener({NewsEvent.class, MilkEvent.class})
    public void newsAndMilkListener(ApplicationEvent event){
        if (event instanceof NewsEvent) {
            System.out.println("李四读 " + event.getSource());
        }

        if (event instanceof MilkEvent) {
            System.out.println("李四喝 " + event.getSource());
        }
    }
}
